package whf.framework.util.var;

import java.util.Iterator;
import java.util.List;
import java.util.Stack;

import whf.framework.entity.Entity;
import whf.framework.util.Utils;

/**
 * QueryString 解析器
 * 变量使用${}标识，其中括号中的就是需要解释的字符串
 * @author King
 * @create Feb 3, 2008 2:15:27 PM
 */
public class QueryStringParser {
	/**
	 * 直接使用BeanUtils.replaceByProperty替换
	 */
	private List<Entity> entities;
	
	private String queryString;
	
	private String result;
	
	public QueryStringParser(String queryString) {
		assert queryString != null: "QueryString cannot be empty!";
		this.queryString = queryString;
	}
	
	public QueryStringParser(String queryString, List<Entity> entities) {
		this(queryString);
		this.entities = entities;
	}
	
	public <T extends Entity> QueryStringParser(String queryString, T entity) {
		this(queryString);
		this.entities = Utils.newArrayList();
		this.entities.add(entity);
	}
	
	public String getResult() {
		if(result == null) {
			this.parse();
		}
		return this.result;
	}
	
	private void parse() {
		Stack<Character> s1 = new Stack<Character>();
		Stack<Character> var = new Stack<Character>();
		for(int i=0; i< this.queryString.length(); i++) {
			char c = this.queryString.charAt(i);
			if(c == '$') {
				
			}
		}
	}
	
	public static void main(String[] args) throws Exception {
		Stack<Character> var = new Stack<Character>();
		var.push('a');
		var.push('b');
		String s = "";
		for(Iterator<Character> vs = var.iterator(); vs.hasNext(); ){
			s += vs.next();
		}
		System.out.println(s);
	}
}
